package api

import (
	"context"
	"hxz_api/basic/globar"
	"hxz_api/handler/request"
	"hxz_rpc/kitex_gen/hxz_rpc/send"
	"net/http"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/common/utils"
)

func Send(ctx context.Context, c *app.RequestContext) {
	var req request.UserReq
	if err := c.Bind(&req); err != nil {
		c.JSON(http.StatusInternalServerError, utils.H{
			"code":    http.StatusInternalServerError,
			"message": err.Error(),
			"data":    false,
		})
		return
	}
	getSend, err := globar.Send.GetSend(ctx, &send.GetSendReq{
		Mobile: req.Mobile,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, utils.H{
			"code":    http.StatusBadRequest,
			"message": err.Error(),
			"data":    false,
		})
		return
	}
	c.JSON(http.StatusOK, utils.H{
		"code":    http.StatusOK,
		"message": "短信发送成功",
		"data":    getSend,
	})

}
